package com.iron.sfm.biz.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iron.common.core.util.R;
import com.iron.sfm.api.entity.SysLog;
import com.iron.sfm.biz.service.SysLogService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 操作日志表
 *
 * @author YT
 * @date 2019-06-27 14:32:35
 */
@RestController
@AllArgsConstructor
@RequestMapping("/log")
public class SysLogController {

  private final SysLogService sysLogService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param sysLog 操作日志表
   * @return
   */
  @GetMapping("/page")
  public R getSysLogPage(Page page, SysLog sysLog) {
    return  R.ok(sysLogService.page(page,Wrappers.query(sysLog)));
  }


  /**
   * 通过id查询操作日志表
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Long id){
    return R.ok(sysLogService.getById(id));
  }

  /**
   * 新增操作日志表
   * @param sysLog 操作日志表
   * @return R
   */
  @PostMapping
  public R save(@Valid @RequestBody SysLog sysLog){
    return R.ok(sysLogService.save(sysLog));
  }

  /**
   * 修改操作日志表
   * @param sysLog 操作日志表
   * @return R
   */
  @PutMapping
  public R updateById(@RequestBody SysLog sysLog){
    return R.ok(sysLogService.updateById(sysLog));
  }

  /**
   * 通过id删除操作日志表
   * @param id id
   * @return R
   */
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Long id){
    return R.ok(sysLogService.removeById(id));
  }

}
